//
//  CityForumCell.m
//  cityStar
//
//  Created by joyban on 15-2-6.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "CityForumCell.h"

@implementation CityForumCell

+(CGFloat)heightOfTableCell
{
    return 140;
}

- (void)awakeFromNib {
    // Initialization code
}
- (IBAction)tiezi_Action:(UIButton *)sender {
    [self.delegate tieziDidBtn:sender];

}
- (IBAction)Fourm_Action:(UIButton *)sender {
    [self.delegate FourmDidBtn:sender];

}

-(void)setDatacpostsModel:(cpostsModel *)model
{
    self.namelabel.text = model.creator_name;
    self.contentLabel.text = model.content;
    NSString * imagePath = @"";
    imagePath = [NSString stringWithFormat:@"%@",model.avatar];
    [self.heardimagel sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.icszx.com/image/c/id/%@/w/30/h/30/m/0",imagePath]] placeholderImage:[UIImage imageNamed:@"品牌列表_主图"]];
    
    NSString * imagePathTwo = [NSString stringWithFormat:@"%@",model.image];
    if(![imagePathTwo isEqualToString:@"0"])
    {
        NSString * imagePathThree = [NSString stringWithFormat:@"%@",model.image[0]];
        [self.footimage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.icszx.com/image/c/id/%@/w/190/h/110/m/0",imagePathThree]] placeholderImage:[UIImage imageNamed:@"品牌列表_主图"]];
    }else{
        self.footimage.hidden = YES;
    }
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithFormat:@"%@",model.create_time] intValue]];

    self.timelabel.text = [self dateStringFromNow:confromTimesp];
    [self.wichlabel setTitle:model.community_name forState:UIControlStateNormal];
}

-(NSString*)dateStringFromNow:(NSDate*)date{
    NSTimeInterval time = -[date timeIntervalSinceNow];
    if (time<0) {
        return @"";
    }else {
        if (time<3600*24) {
            if (time>=0.0 && time <60.0) {
                return @"刚刚";
            }else if (time>=60.0 && time <60.0*60.0) {
                return [NSString stringWithFormat:@"%d分钟前",(int)time/60];
            }else if (time>=3600.0 && time <3600.0*24) {
                return [NSString stringWithFormat:@"%d小时前",(int)time/3600];;
            }
        }else {
            
            NSCalendar* calendar = [NSCalendar currentCalendar];
            NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSWeekCalendarUnit fromDate:date toDate:[NSDate date] options:0];
            if ([components year]>0) {
                int month = [components year]*12+[components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components month]>0){
                int month = [components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components week]>0){
                return [NSString stringWithFormat:@"%d周前",[components week]];
            }else if([components day]>0){
                return [NSString stringWithFormat:@"%d天前", [components day]];
            }
        }
    }
    return @"";
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
